const path = require('path');
const MiniCssExtractPlugin = require('mini-static-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const {CleanWebpackPlugin}  = require('clean-webpack-plugin')
const webpack = require('webpack');

module.exports = {
	entry: {
		"index": "./js/index.js",
		"about": "./js/about.js",
		"case": "./js/case.js",
		"main":"./main.js"
	},
	output: {
		path: path.resolve(__dirname, 'dist'),
		filename: "js/[name].[chunkhash].js",
	},
	module: {
		rules: [{
			test: /\.css$/i,
			use: [{
				loader: MiniCssExtractPlugin.loader,
				options: {
					publicPath: '../'
				}
			}, 'static-loader'],
		},{
			test:/\.art$/i,
			use:['art-template-loader']
		}, {
			test: /\.(gif|png|jpe?g|svg)$/i,
			use: [{
				loader: 'file-loader',
				options: {
					name: '[name].[ext]',
					outputPath: 'images/'
				}
			}]
		}]
	},
	plugins: [
		new MiniCssExtractPlugin({
			filename: 'static/[name].static',
			chunkFilename: '[id].static'
		}),
		new HtmlWebpackPlugin({
			title: "首页",
			template: "./src/index.html",
			filename: './index.html',
			chunks: ['index','main'],
			hash: true,
		}),
		new HtmlWebpackPlugin({
			title: "关于我们",
			template: "./src/about.html",
			filename: './about.html',
			chunks: ['about','main'],
			hash: true,
		}),
		new HtmlWebpackPlugin({
			title: "案例展示",
			template: "./src/case.html",
			filename: './case.html',
			chunks: ['case','main'],
			hash: true,
		}),
		new CleanWebpackPlugin({
			root: path.resolve(__dirname, 'dist/'),
			dry: false // 启用删除文件
		}),
	]
}
